package com.gmall

import java.util.Properties

import com.gmall.utils.PropertiesUtil
import org.apache.kafka.clients.producer.{KafkaProducer, ProducerRecord}


/**
 * <p>文件名称: kafka生产者 </p>
 * <p>描述:  </p>
 * <p>创建时间: 2020/10/17</p>
 * @author <a href="mail to: 1034652894@qq.com" rel="nofollow">Demik Qin</a>
 * @version v1.0
 * @update [序号][日期YYYY-MM-DD] [更改人姓名][变更描述]
 */
object MyKafkaUtil {

    private val kafkaServers: String = PropertiesUtil.getValue("kafka.bootstrap.servers")

    val props = new Properties()
    props.put("bootstrap.servers", kafkaServers)
    props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer")
    props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer")

    // 创建一个生产者
    private val producer = new KafkaProducer[String, String](props)

    def sendToKafka(topic: String, content: String): Unit = {
        producer.send(new ProducerRecord[String, String](topic, content))

    }


}
